package com.drpclub.gamebackend.common.utils;

import cn.hutool.captcha.generator.MathGenerator;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author dongruipeng
 * @Descrpition
 * @date 2019year 12month12day  19:30:36
 */
//TODO temp ==> redis
public class Cache {
    private static final HashMap<String, String> codeMap = new HashMap<>();

    public static boolean verifyCode(String key, String value) {
        synchronized (codeMap) {
            if (!codeMap.containsKey(key)) {
                return false;
            }

            final boolean flag = new MathGenerator().verify(codeMap.get(key), value);
            if (flag) {
                codeMap.remove(key);
            }
            return flag;
        }
    }

    public static HashMap<String, String> getCodeMap() {
        return codeMap;
    }
}
